home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / WINGUI / KBDPROC.C < prev    next >
C/C++ Source or Header  |  1996-01-23  |  2KB  |  71 lines

  1. /* Keyboard procedure used to sub-class all windows which can be
  2.  * tab stops.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include "wingui\wizunzip.h"
  7.  
  8. /* Keyboard procedure
  9.  * This function allows the user to tab and back-tab among the 
  10.  * between the listbox and message window.
  11.  * It traps VK_TAB messages and sets the
  12.  * focus on the next or previous window as required.
  13.  * Skip any disabled windows.
  14.  */
  15. long WINAPI KbdProc(HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam)
  16. {
  17. #ifndef WIN32
  18. int nID = GetWindowWord(hWnd, GWW_ID); /* child window ID no. */
  19. #else
  20. int nID = GetWindowLong(hWnd, GWL_ID); /* child window ID no. */
  21. #endif
  22. int nTabStopTableIndex = nID - TABSTOP_ID_BASE;
  23. int nNextTabStopTableIndex = nTabStopTableIndex;
  24.  
  25. if (wMessage == WM_KEYDOWN)
  26.    {
  27.    if (wParam == VK_TAB)
  28.       {
  29.       int nRelIndex = /* forward or backward ? */
  30.           (int)(GetKeyState(VK_SHIFT) < 0 ? -1 : 1);
  31.  
  32.       do {
  33.          nNextTabStopTableIndex += nRelIndex;
  34.          if (nNextTabStopTableIndex < 0)
  35.             nNextTabStopTableIndex = TABSTOP_TABLE_ENTRIES-1;
  36.          else if (nNextTabStopTableIndex >= TABSTOP_TABLE_ENTRIES)
  37.             nNextTabStopTableIndex = 0;
  38.  
  39.       } while (!IsWindowEnabled(TabStopTable[nNextTabStopTableIndex].hWnd));
  40.  
  41.    SetFocus(TabStopTable[nNextTabStopTableIndex].hWnd);
  42.    }
  43. else if (wParam == VK_F1)
  44.    {
  45.    /* If Shift-F1, turn help mode on and set help cursor */
  46.    if (GetKeyState(VK_SHIFT)<0)
  47.       {
  48.       uf.fHelp = TRUE;
  49.       SetCursor(hHelpCursor);
  50.       }
  51.    else
  52.       {
  53.       /* If F1 without shift, then call up help main index topic */
  54.       WinHelp(hWndMain, szHelpFileName, HELP_INDEX, 0L);
  55.       }
  56.    }
  57. else if ((wParam == VK_ESCAPE) && uf.fHelp)
  58.    {
  59.    /* Escape during help mode: turn help mode off */
  60.    uf.fHelp = FALSE;
  61. #ifndef WIN32
  62.    SetCursor((HCURSOR)GetClassWord(hWndMain,GCW_HCURSOR));
  63. #else
  64.    SetCursor((HCURSOR)GetClassLong(hWndMain,GCL_HCURSOR));
  65. #endif
  66.    }
  67. }
  68. return CallWindowProc(TabStopTable[nTabStopTableIndex].lpfnOldFunc,
  69.                       hWnd, wMessage, wParam, lParam);
  70. }
  71.